$(document).ready(function(){
	
	$.validator.addMethod("minFloor",function(value,element,params){
		if(value=="") return true;
		if(parseInt(value)<parseInt(params.val())){
			return false;
		}
		return true;
	},"不得低于楼层数");
	
	$.validator.addMethod("infoId" , function(value ,element , params){
		if(!(/^[0-9a-zA-Z]*$/.test(value))){
			return false;
		}
		return true;
	},"请输入数字或字母");

	if($("#publishform")){
		$("#publishform").validate({
			rules: {
				infoid:{
					infoId:true
				},
				plaza: {
					required: true,
					maxlength:50
				},
				square: {
					/*required: true,*/
					number:true
				},
				style1: {
					required: true,
					digits:true
				},
				style2: {
					required: true,
					digits:true
				},
				style3: {
					required: true,
					digits:true
				},
				floor1: {
					required: true,
					digits:true
				},
				floor2: {
					minFloor : $("#floor1"),
					digits:true
				},
				age: {
					digits:true
				},
				price: {
					required: true,
					number:true
				},
				detail: {
					maxlength:200
				}
			},
			messages: {
				infoid:{
					infoId:"请输入数字或字母"
				},
				plaza: {
					required: "请输入小区名",
					maxlength:"小区名不要超过50个字"
				},
				square: {
					/*required: "请输入面积",*/
					number:"请填入阿拉伯数字"
				},
				style1: {
					required: "请输入几室",
					digits:"请填入阿拉伯数字"
				},
				style2: {
					required: "请输入几厅",
					digits:"请填入阿拉伯数字"
				},
				style3: {
					required: "请输入几卫",
					digits:"请填入阿拉伯数字"
				},
				floor1: {
					required: "请输入楼层",
					digits:"请填入阿拉伯数字"
				},
				floor2: {
					minFloor : "不得低于楼层数",
					digits:"请填入阿拉伯数字"
				},
				age: {
					digits:"请填入阿拉伯数字"
				},
				price: {
					required: "请输入售价",
					digits:"请填入阿拉伯数字"
				},
				detail: {
					maxlength:"描述不要超过200个字"
				}
			},
			submitHandler: function(form) {  
				$("#buttondiv").css("display" , "none");
				$("#fbmsg").css("display" , "");
				form.submit();  
			}
		});

		$("#submitbtn2").bind("click" , function(){
			$("#ispublic").val(1);
			$("#publishform").trigger("submit");
		});

		$("#showcompare").bind("click" , function(){
			var plaza = $("#plaza").val();
			if(plaza==""){alert("请输入小区名称");}
			else{
				window.open("compare_rhadd.php?plaza="+plaza);
			}
		});
	}
	
	
});